package com.anlogic.sdk.programfpga;

import com.anlogic.sdk.openocd.model.RemoteTarget;
import com.anlogic.sdk.utils.options.ChipType;

enum Speed {
	L0_90Kbps,
	L1_100Kbps,
	L2_200Kbps,
	L3_400Kbps,
	L4_600Kbps,
	L5_1Mbps,
	L6_2Mbps,
	L7_3Mbps,
	L8_6Mbps;
}

public class ProgramFPGAModel {
	public static final String LOCAL_NAME = "Local";
	public static final String LOCALHOST = "localhost";
	public static final String LOCALHOST_IP = "127.0.0.1";
	public static final String PORT = "5555";
	
	private String chip = "";
	private String host = LOCALHOST;
	private String port = PORT;
	private String bitFile = "";
	private String mode = "jtag";
	private Speed spd = Speed.L6_2Mbps;
	private int cable = 0;
	
	private RemoteTarget target;
	
	private boolean useOldMode = true;
	
	public boolean isLocal() {
		if (this.host.equals(LOCALHOST) || this.host.equals(LOCALHOST_IP)) {
			return true;
		}
		return false;
	}
	
	public String getChip() {
		return this.chip;
	}
	
	public void setChip(String chip) {
		this.chip = chip;
	}
	
	public String getHost() {
		return this.host;
	}
	
	public void setHost(String host) {
		this.host = host;
	}
	
	public String getPort() {
		return this.port;
	}
	
	public void setPort(String port) {
		this.port = port;
	}
	
	public String getBitFile() {
		return this.bitFile;
	}
	
	public void setBitFile(String bitFile) {
		this.bitFile = bitFile;
	}
	
	public String getMode() {
		return this.mode;
	}
	
	public void setMode(String mode) {
		this.mode = mode;
	}
	
	public int getSpeedID() {
		return this.spd.ordinal() + 1;
	}
	
	public Speed getSpeed() {
		return this.spd;
	}
	
	public void setSpeed(Speed spd) {
		this.spd = spd;
	}
	
	public int getCable() {
		return this.cable;
	}
	
	public void setCable(int cable) {
		this.cable = cable;
	}
	
	public RemoteTarget getRemoteTarget() {
		return this.target;
	}
	
	public void setRemoteTarget(RemoteTarget target) {
		this.target = target;
	}
	
    public boolean useOldMode() {
    	return useOldMode;
    }
    
    public void setUseOldMode(boolean useOldMode) {
		this.useOldMode = useOldMode;
	}
    
    public boolean isUseOldMode(String chipType) {
    	if (chipType == null || chipType.isEmpty()) {
			return true;
		}
    	if (ChipType.isDr1(chipType) || ChipType.isDR1M350(chipType)) {
    		return false;
		}
    	return true;
    }
}
